import 'package:auto_route/annotations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sonora/utils/sj_text_style.dart';
import 'package:sonora/views/appbar/sj_appbar.dart';
import 'package:webview_flutter/webview_flutter.dart';

@RoutePage()
class SjWebviewPage extends StatefulWidget {
  final String url;
  final String title;
  const SjWebviewPage({super.key, required this.url, required this.title});

  @override
  State<SjWebviewPage> createState() => _SjWebviewPageState();
}

class _SjWebviewPageState extends State<SjWebviewPage> {
  // 1
  late WebViewController controller;
  @override
  void initState() {
    // 2
    controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse(widget.url));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        extendBodyBehindAppBar: true, // 使内容延伸到导航
        appBar: SjAppbar(
          title: Text(
            widget.title,
            style: SjTextStyle.customFontBlack20,
          ),
          backgroundColor: Colors.transparent, // 设置导航栏背景为透明
          elevation: 0, // 去除导航栏阴影
          leading: IconButton(
            icon: Image.asset('assets/images/nav_back.png'), // 左侧按钮
            onPressed: () {
              // 处理返回逻辑
              Navigator.of(context).pop();
            },
          ),
        ),
        body: SafeArea(
          child: Column(
          children: [
            // 3
            Expanded(child: WebViewWidget(controller: controller))
          ],
        ),
        ));
  }
}
